/**
 * 
 */
package view;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import model.Venda;

import org.jvnet.substance.skin.SubstanceNebulaLookAndFeel;

import controller.VendaServicos;

/**
 * @author Eve
 * 
 */
public class TelaGerenteGUI implements Observer {

	private VendaServicos vendaServicos;
	private GerenteGUI gerenteGUI;

	public TelaGerenteGUI(VendaServicos vendaServicos2, Venda venda) {
		this.vendaServicos = vendaServicos2;
		venda.addObserver(this);
		Runnable threadGUI = new Runnable() {
			public void run() {
				criarJanela();
			}
		};

		SwingUtilities.invokeLater(threadGUI);
	}

	private void criarJanela() {

		try {
			UIManager.setLookAndFeel(new SubstanceNebulaLookAndFeel());
			JFrame.setDefaultLookAndFeelDecorated(true);
			JDialog.setDefaultLookAndFeelDecorated(true);
			SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					try {
						gerenteGUI = new GerenteGUI(vendaServicos.listarVendasDia());
					} catch (Throwable e) {
						e.printStackTrace();
					}
				}
			});
		} catch (UnsupportedLookAndFeelException e1) {
			e1.printStackTrace();
		}
	}

	@Override
	public void update(Observable venda1, Object valor) {
		if (venda1 instanceof Venda) {
			gerenteGUI.atualizarTela(vendaServicos.listarVendasDia());
		}
	}

}
